﻿using System;
using ReAnimation.Helpers.IoC;
using ReAnimation.MVP.Models.Interfaces;
using ReAnimation.MVP.ViewInterfaces;
using System.Diagnostics;
using ReAnimation.Infrastructure.Services.Interfaces;
using ReAnimation.Domain;
using ReAnimation.Helpers.WinForms;
using System.Linq;

namespace ReAnimation.MVP.Presenters
{
    public class MainPresenter : BasePresenter<IMainView>
    {
        private readonly IMainModel _mainModel;
        private readonly ILazyInject<ILoginView> _loginDialogInjector;
        private readonly ILazyInject<IChooseMoleculeView> _chooseMoleculeViewInjector;
        private readonly ILazyInject<INewMoleculeDialogView> _newMoleculeDialogView;
        private readonly ILazyInject<IOpenFileDialogView> _openFileDialogViewInjector;
        private readonly ILazyInject<IOpenBabelService> _openBabelService;
        private readonly ILazyInject<IZMatrixService> _zMatrixService;
        private readonly ILazyInject<INotifier> _notifier;

        protected override void InitView()
        {
            _view.LinkingAtomsPairSelected += _view_LinkingAtomsPairSelected;
            _view.CreateNewMolecule += ViewOnCreateNewMolecule;
            _view.DeleteMolecule += ViewOnDeleteMolecule;
            _view.LoadMolecule += ViewOnLoadMolecule;
        }

        void ViewOnLoadMolecule(object sender, EventArgs e)
        {
            
        }

        private void ViewOnDeleteMolecule(object sender, EventArgs eventArgs)
        {
            
        }

        private void ViewOnCreateNewMolecule(object sender, EventArgs eventArgs)
        {
            _newMoleculeDialogView.Get().ShowViewDialog();
        }

        void _view_LinkingAtomsPairSelected(object sender, EventArgs e)
        {
            _view.ShowAtomsLinkingDialog();
        }

        public MainPresenter(IMainModel mainModel, 
                             ILazyInject<ILoginView> loginDialogInjector, 
                             ILazyInject<IChooseMoleculeView> chooseMoleculeViewInjector,
                             ILazyInject<INewMoleculeDialogView> newMoleculeDialogView,
                             ILazyInject<IOpenFileDialogView> openFileDialogViewInjector,
                             ILazyInject<IOpenBabelService> openBabelService,
                             ILazyInject<INotifier> notifier,
                             ILazyInject<IZMatrixService> zMatrixService)
        {

            _mainModel = mainModel;
            _openBabelService = openBabelService;
            _zMatrixService = zMatrixService;
            _notifier = notifier;
            _newMoleculeDialogView = newMoleculeDialogView;
            _chooseMoleculeViewInjector = chooseMoleculeViewInjector;
            _loginDialogInjector = loginDialogInjector;
            _openFileDialogViewInjector = openFileDialogViewInjector;
            _mainModel.CurrentMoleculeChanged += currentMoleculeChangedHandler;
        }

        private void currentMoleculeChangedHandler(object sender, EventArgs e)
        {

        }
    }
}